package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //根据第K场考试排序
    public int[][] sortTheStudents(int[][] score, int k) {
        quickSort(score, 0, score.length-1, k);
        return score;
    }

    public void quickSort(int[][] score, int l, int r, int k){
        if(l < r){
            int key = partition(score, l, r, k);
            quickSort(score, l, key-1, k);
            quickSort(score, key+1, r, k);
        }
    }

    public int partition(int[][] score, int l, int r, int k) {
        int[] base = score[l];
        while (l < r) {
            while (l < r && score[r][k] <= base[k]) r--;
            score[l] = score[r];
            while (l < r && score[l][k] >= base[k]) l++;
            score[r] = score[l];
        }
        score[l] = base;
        return l;
    }
}
